/*
 * @Author: wuzhouhai wzh200x@126.com
 * @Date: 2024-07-09 11:57:57
 * @LastEditors: wuzhouhai wzh200x@126.com
 * @LastEditTime: 2025-01-16 12:02:34
 * @FilePath: \dwys_web\extensions\phoenix-plugin-client\assets\core\utils\Utils.String.ts
 * @Description:
 */
// import zlib from "zlib";
import * as pako from 'pako';
import { weAtob, weBtoa } from './weapp-jwt';
export class UtilsString {
    public static zlibEncode(str: string): string {
        const compressedData = pako.deflate(str);
        //@ts-ignore
        return weBtoa(String.fromCharCode.apply(null, compressedData));
        // return zlib.deflateSync(str).toString('base64');
    }

    public static zlibDecode(str: string): string {
        // 步骤1：将Base64编码解码为Uint8Array
        const binaryData = weAtob(str);
        const uint8Array = new Uint8Array(binaryData.length);
        for (let i = 0; i < binaryData.length; i++) {
            uint8Array[i] = binaryData.charCodeAt(i);
        }
        // 步骤2：使用pako.inflate解压Uint8Array
        // @ts-ignore
        const decompressedData = pako.inflate(uint8Array, { to:'string', chunkSize:1024*1024});
        return decompressedData;
    }
}
